package com.topscore.uke.mvp.presenters;

import com.topscore.uke.entities.CommodityData;
import com.topscore.uke.mvp.contractors.GetCommodityPageDataContractor;
import com.topscore.uke.mvp.model.GetCommodityPageModel;
import com.topscore.uke.network.BaseResponse;

import java.util.List;

/**
 * Created by 71468 on 2018/3/13.
 */

public class GetCommodityPresenter implements GetCommodityPageDataContractor,
        GetCommodityPageDataContractor.Presenter {
    private View mView;
    private Model mModel;

    public GetCommodityPresenter(View mView) {
        this.mView = mView;
        mModel = new GetCommodityPageModel(new Listener() {


            @Override
            public void onGetDataSuccess(BaseResponse<List<CommodityData>> response) {
                mView.onGetDataSuccess(response.getData());
            }

            @Override
            public void onError(int errorCode, String errorMessage) {
                mView.onFail(errorCode,errorMessage);
            }

            @Override
            public void onComplete() {
                mView.onLoadFinished();
            }
        });
    }

    @Override
    public void getCommodityData() {
        mView.onLoading("正在获取商品信息");
        mModel.getCommodityData();
    }
}
